const Router = require('koa-router')
const userDao = require('../dao/userDao')
const router = new Router();

router.get('/user/check/:username/:password' , async(ctx) => {
    const { username , password } = ctx.params;
    let res = await userDao.check(username,password)
    if (res[0].count === 0) {
        ctx.body = 400;
    } else {
        ctx.body = 200;
    }
})

router.get('/user/:id' , async (ctx) => {
    const { id } = ctx.params
    ctx.body = await userDao.getById(id)
})

router.get('/user/regist/:username/:password/:email/:payPassword' , async(ctx) => {
    const { username , password , email , payPassword } = ctx.params;
    ctx.body = await userDao.insert(username , password , email , payPassword)
})

router.get('/user/:username/:password' , async (ctx) => {
    const { username , password } = ctx.params
    ctx.body = await userDao.getIdByUserPwd(username,password)
})



module.exports = router;